package main

import "strconv"

type PaymentStrategy interface {
	Pay(amount float64)
}

type CreditCardPay struct {
}

func (c CreditCardPay) Pay(amount float64) {
	println("信用卡支付: " + strconv.FormatFloat(amount, 'f', 2, 64) + "元")
}

type WeiXinPay struct {
}

func (w WeiXinPay) Pay(amount float64) {
	println("微信支付: " + strconv.FormatFloat(amount, 'f', 2, 64) + "元")
}

type Alipay struct {
}

func (a Alipay) Pay(amount float64) {
	println("支付宝支付: " + strconv.FormatFloat(amount, 'f', 2, 64) + "元")
}

type Context struct {
	PaymentStrategy PaymentStrategy
}

func (c *Context) SetStrategy(strategy PaymentStrategy) {
	c.PaymentStrategy = strategy
}

func (c *Context) Pay(amount float64) {
	c.PaymentStrategy.Pay(amount)
}

func main() {
	pay := &Context{}
	pay.SetStrategy(Alipay{})
	pay.Pay(100.0)
	pay.SetStrategy(WeiXinPay{})
	pay.Pay(200.0)
}
